from data_structure.grammar import Grammar
from analyze_utils import (
    eliminate_left_recursion,
    solve_first,
    solve_follow,
    predictive_analysis
)
from lib import epsilon


def main():
    g = Grammar([
        "E -> E + T | T",
        "T -> T * F | F",
        "F -> (E) | id",
    ])
    # 解析产生式
    g.parse_productions()
    # 消除左递归
    eliminate_left_recursion(g)

    # # 求解 First 与 Follow 集合
    solve_first(g)
    solve_follow(g)
    # # 打印 First 与 Follow 集合
    g.show_first_set()
    g.show_follow_set()

    # 预测分析
    # predictive_analysis(g, 'E', 'id * id + id')
    predictive_analysis(g, 'E', '(id + id * (id)) + id')


if __name__ == '__main__':
    main()
